package top.zuli.package02.homework02;

/**
 * 位移运算
 */
public class Demo10 {
    public static void main(String[] args) {
        //左位移
        System.out.println(2<<1);
        //查看二进制代码Integer.toBinaryString(int n)将整数转为二进制代码
        System.out.println(Integer.toBinaryString(2<<1));
        //左位移
        System.out.println(-2<<1);
        System.out.println(Integer.toBinaryString(-2<<1));

        //右位移
        System.out.println(3>>1);
        System.out.println(Integer.toBinaryString(3>>1));
        System.out.println(-3>>1);
        System.out.println(Integer.toBinaryString(-3>>1));

        //无符号右位移
        System.out.println(4>>>1);
        System.out.println(Integer.toBinaryString(4>>>1));
        System.out.println(-4>>>1);
        System.out.println(Integer.toBinaryString(-4>>>1));

        //按位与
        System.out.println(6&3);
        System.out.println(Integer.toBinaryString(6&3));

        //按位或
        System.out.println(6|3);
        System.out.println(Integer.toBinaryString(6|3));

        //异或
        System.out.println(6^3);
        System.out.println(Integer.toBinaryString(6^3));

        //取反
        System.out.println(~6);
        System.out.println(Integer.toBinaryString(~6));
    }
}